package com.nuc.kl.module.kpoint.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nuc.kl.base.DaoSupportImpl;
import com.nuc.kl.module.kpoint.dao.KPointDao;
import com.nuc.kl.module.kpoint.entity.Knowledge;
import com.nuc.kl.module.kpoint.entity.KnowledgeLog;
import com.nuc.kl.module.kpoint.service.KPointService;
import com.nuc.kl.module.kpoint.service.KnowledgeLogService;
import com.nuc.kl.module.usermanager.entity.People;
import com.nuc.kl.module.usermanager.entity.Teacher;

@Service
@Transactional
public class KPointServiceImpl extends DaoSupportImpl<Knowledge> implements KPointService{

	@Resource
	private KPointDao kpointDao;
	@Resource
	private KnowledgeLogService knowledgeLogService;

	
	
	public void deleteByIds(String ids) {
		String[] arrId = ids.split(",");
		for (String str : arrId) {
			this.delete(Long.parseLong(str));
		}
	}

	public List<Knowledge> searchPageByIndex(int start, int number,
			Map<String ,Object> m) {
		
		List<Knowledge> list = kpointDao.searchPageByIndex(start,number,m);
			
		return list;
	}
	
	/**
	 * 重写增删改方法 添加知识点日志的记录 
	 */
	public void save(Knowledge entity,People people) {
		knowledgeLogService.save("save",entity,people);
		entity.setStatus(1);
		super.save(entity);
	};
	
	public void toReCycleBin(Long id,People people) {
		Knowledge entity = this.getById(id);
		knowledgeLogService.save("delete",entity,people);
		entity.setStatus(4);
		super.update(entity);
	};
	
	public void update(Knowledge entity,People people) {
		
		knowledgeLogService.save("update",entity,people);
		
		entity.setStatus(1);
		super.update(entity);
	};
	
	public void updateStatus(Knowledge entity,People people) {
		knowledgeLogService.save("check",entity,people);
		super.update(entity);
	}

	public List<Knowledge> loadByNav(long id) {
		
		return kpointDao.loadByNav( id);
	}

	public Long editTimes(long id) {
		return knowledgeLogService.countByKnowledgeId(id);
	}

	public String getCreator(long id) {
		return knowledgeLogService.getCreatorByKnowledgeId(id);
	}

	public Date getResentTime(long id) {
		return knowledgeLogService.getResentTime(id);
	}

	public void reCycle(Knowledge model, People people) {
		
		knowledgeLogService.save("reCycle",model,people);
		model.setStatus(1);
		super.update(model);
	
	}
	
	
}
